package com.mybatis.test.utils;

import java.util.List;

import com.mybatis.plugin.test.model.Order;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import com.automapper.utils.FieldFacade;
import com.automapper.utils.ObjectFacade;

public class GenIfElseString {

	@Test
	public void test() {
		ObjectFacade objectFacade = new ObjectFacade(new Order());
		List<FieldFacade> fieldFacades = objectFacade.getFieldFacades();
		
		int length = fieldFacades.size();
		
		String str = "";
		int index = 0;
		for (int i = 0; i < length; i++) {
			FieldFacade fieldFacade = fieldFacades.get(i);
			String fieldName = fieldFacade.getFieldName();
			String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
			
			if (StringUtils.equals("id", fieldName)) {
				continue;
			}
			
			if (fieldFacade.getJavaType().getName().equals(String.class.getName())) {
				str += "if (StringUtils.isBlank(header." + methodName + "())) {" +
							 "list.add(\"\"); " +
							 "} else {" +
							 "list.add(String.format(VALUE, ParameterConstants.PARAM, "+ index +", \"" + fieldName + "\"));" +
							 "} ";
			} else if (fieldFacade.getJavaType().getName().equals(Byte.class.getName())) {
				str += "if (header." + methodName + "() == 0) {" +
						"list.add(\"0\");" +
						"} else {" +
						"list.add(String.format(VALUE, ParameterConstants.PARAM, " + index +", \"" + fieldName + "\"));" +
						"} ";
			} else {
				str += "if (header." + methodName + "() == null) {" +
						"list.add(\"0\");" +
						"} else {" +
						"list.add(String.format(VALUE, ParameterConstants.PARAM, " + index +", \"" + fieldName + "\"));" +
						"} ";
			}
			
			++index; 
		}
		
		System.out.println(str);
	}
}
